package com.qf.controller;

import com.qf.entity.Data;
import com.qf.entity.User;
import com.qf.service.UserService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;


@CrossOrigin("*")
@RestController
public class CheckNameController {
    private UserService userService;
    public CheckNameController(UserService userService){

        this.userService = userService;

    }
    @RequestMapping("/CheckName")
    @ResponseBody
    private Data CheckName(HttpSession session,String username){

        //调用service方法
        User isExist = userService.QueryByName(username);
        Data data = null;
        //是否存在
        if(isExist !=null){

            data = new Data(1, "用户已存在，请重新输入");
            return data;

        }else {

            data = new Data(-1,"恭喜你，用户名可用");
            return data;

        }


    }


}
